package com.ebt.m.msgnote.view;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.BaseListView;
import com.ebt.m.commons.buscomponent.listview.ISectionFactory;
import com.ebt.m.commons.buscomponent.listview.IView;
import com.ebt.m.commons.utils.ActivityUtils;
import com.ebt.m.msgnote.MsgItemView;
import com.ebt.m.msgnote.bean.MsgTypeBean;
import com.ebt.m.msgnote.presenter.MsgCenterListPresenter;

/**
 * 消息中心首页
 * Created by allen on 2018/7/27 11:04.
 */
public class MsgCenterListView extends BaseListView<MsgCenterListPresenter> {
    public MsgCenterListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MsgCenterListView(Context context) {
        super(context);
    }

    public MsgCenterListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mRefreshLayout.setRefreshEnable(false);
        mRefreshLayout.setRefreshNeeded(false);

    }

    @Override
    protected ISectionFactory createViewFactory() {
        return viewType -> {
            MsgItemView itemView = new MsgItemView(getContext());
            itemView.setOnClickViewListener(onClickListner);
            return itemView;
        };
    }


    @Override
    protected MsgCenterListPresenter createPresenter() {
        return new MsgCenterListPresenter(getContext(), this);
    }

    @Override
    public void loadNext() {

    }

    @Override
    protected boolean createFootView() {
        return false;
    }

    public IView.OnClickListner onClickListner = new IView.OnClickListner() {
        @Override
        public void onClick(View view, Object... args) {
            switch (view.getId()) {
                case R.id.rlItemViewMsg:
                    MsgTypeBean bean = (MsgTypeBean) args[0];
                    Bundle bundle = new Bundle();
                    bundle.putInt("type", bean.getType());
                    bundle.putString("name", bean.getName());
                    ActivityUtils.launchActivity(getContext(), TypeMsgActivity.class, bundle);
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onLongClick(View view, Object... args) {

        }
    };

    @Override
    protected View configEmptyView() {
        View emptyContent = LayoutInflater.from(getContext()).inflate(R.layout.layout_product_search_empty, null);
        ImageView imageView = (ImageView) emptyContent.findViewById(R.id.img_empty);
        TextView textView = (TextView) emptyContent.findViewById(R.id.mession_empty);
        imageView.setBackgroundResource(R.drawable.ic_message_center_empty);
        textView.setText("暂无消息");
        return emptyContent;
    }

    @Override
    protected int setListviewColor() {
        return ContextCompat.getColor(getContext(), R.color.bg_color_F5F5F5);
    }
}
